﻿using System.Reflection;

namespace GrainManage
{
    public sealed class PageSettings
    {
        private static readonly string cmdGet = "SELECT Size FROM PageSettings WHERE ItemName=?";
        private static readonly string cmdUpdate = "UPDATE PageSettings SET Size=? WHERE ItemName=?";

        public static int ContactNameCount
        {
            get
            {
                return Get("ContactName");
            }
            set
            {
                Set("ContactName", value);
            }
        }

        public static int ContactAddressCount
        {
            get
            {
                return Get("ContactAddress");
            }
            set
            {
                Set("ContactAddress", value);
            }
        }

        public static int ContactAreaCount
        {
            get
            {
                return Get("ContactArea");
            }
            set
            {
                Set("ContactArea", value);
            }
        }

        public static int ContactTelephoneCount
        {
            get
            {
                return Get("ContactTelephone");
            }
            set
            {
                Set("ContactTelephone", value);
            }
        }

        public static int GrainTypeCount
        {
            get
            {
                return Get("GrainType");
            }
            set
            {
                Set("GrainType", value);
            }
        }

        public static int TradeTypeCount
        {
            get
            {
                return Get("TradeType");
            }
            set
            {
                Set("TradeType", value);
            }
        }

        public static int PriceTypeCount
        {
            get
            {
                return Get("PriceType");
            }
            set
            {
                Set("PriceType", value);
            }
        }

        public static int ChildDistrictCount
        {
            get
            {
                return Get("ChildDistrict");
            }
            set
            {
                Set("ChildDistrict", value);
            }
        }

        public static int ContactPageSize
        {
            get
            {
                return Get("ContactPage");
            }
            set
            {
                Set("ContactPage", value);
            }
        }

        public static int ImagePageSize
        {
            get
            {
                return Get("ImagePage");
            }
            set
            {
                Set("ImagePage", value);
            }
        }

        public static int CommonPageSize
        {
            get
            {
                return Get("CommonPage");
            }
            set
            {
                Set("CommonPage", value);
            }
        }

        public static int Get(string itemName)
        {
            var obj = SQLite.ExecuteScalar(cmdGet, itemName);
            int count = System.Convert.ToInt32(obj);
            return count;
        }

        public static void Set(string itemName, int value)
        {
            SQLite.Execute(cmdUpdate, value, itemName);
        }
    }
}
